document.getElementById("charge2").onclick=function(){
	window.open ("charge2.html?type=charge&title=会员充值", "_blank", "height=600, width=800, top=160, left=200, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
}
document.getElementById("addMem").onclick=function(){
	window.open ("addUser.html?action=general&type=POST", "_blank", "height=400, width=600, top=160, left=200, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
}
function createLine(data){
	$("tbody>tr").remove()
				var tab=document.getElementById("tx")
				var tr=document.createElement("tr")

				var td=document.createElement("td")
				td.textContent="总充值金额"
				tr.appendChild(td)
				var td=document.createElement("td")
				td.textContent=data.all_charge
				tr.appendChild(td)
			
				var td=document.createElement("td")
				td.textContent="现金充值金额"
				tr.appendChild(td)


				var td=document.createElement("td")
				td.textContent=data.cash_charge
				tr.appendChild(td)
			
				var td=document.createElement("td")
				td.textContent="扫码充值金额"
				tr.appendChild(td)
				var td=document.createElement("td")
				td.textContent=data.scan_charge
				tr.appendChild(td)
			
		
				tab.appendChild(tr)
			


				var tab=document.getElementById("tab")
				for(var i=0;i<data.content.length;i++){
					var tr=document.createElement("tr")

					var td=document.createElement("td")
					console.log(111)
					td.textContent=jiami(data.content[i].username,data.user_type)
					tr.appendChild(td)

					var td=document.createElement("td")
					td.textContent=data.content[i].chinese_name
					tr.appendChild(td)

					var td=document.createElement("td")
					td.textContent=data.content[i].cash
					tr.appendChild(td)

				var td=document.createElement("td")
				var span=document.createElement("span")
				if(data.content[i].charge_type==="扫码充值"){
					span.className="btn btn-xs btn-primary"
				}
				else if(data.content[i].charge_type==="积分赠送"){
					span.className="btn btn-xs btn-warning"
				}
				else if(data.content[i].charge_type==="在线充值"){
					span.className="btn btn-xs btn-success"
				}
				else{
					span.className="btn btn-xs btn-danger"
				}
				span.textContent=data.content[i].charge_type
				td.appendChild(span)
				tr.appendChild(td)

					var td=document.createElement("td")
					td.textContent=data.content[i].addition
					tr.appendChild(td)

					var td=document.createElement("td")
					td.textContent=data.content[i].real_value
					tr.appendChild(td)

					var td=document.createElement("td")
					td.textContent=data.content[i].level +"星级会员"
					tr.appendChild(td)

					var td=document.createElement("td")
					td.textContent=data.content[i].number
					tr.appendChild(td)

					var td=document.createElement("td")
					td.textContent=data.content[i].date
					tr.appendChild(td)

					var td=document.createElement("td")
					var b=document.createElement("button")
					b.setAttribute("username",data.content[i].username)
					b.setAttribute("status",data.content[i].status)
					if(data.content[i].operator_type==="站长"){
						b.className="btn btn-xs btn-danger"
					}
					else if(data.content[i].operator_type==="管理员"){
						b.className="btn btn-xs btn-warning"
					}
					else{
						b.className="btn btn-xs btn-success"
					}
					b.textContent=data.content[i].operator_type
					
					td.appendChild(b)
					tr.appendChild(td)

					var td=document.createElement("td")
					if (data.content[i].operator==""){
						td.textContent="--"
					}
					else{
						td.textContent=data.content[i].operator
					}
					tr.appendChild(td)

					var td=document.createElement("td")
					td.textContent=data.content[i].operator_chinesename
					tr.appendChild(td)

					tab.appendChild(tr)
				

			}
}
function getList(){
	$.ajax({
		"url":"/user_admin/",
		"error":errorAjax,
		"beforeSend":start_load_pic,
		"complete":stop_load_pic,
		"dataType":"jsonp",
		"success":function(data){
			if(responseCheck(data)){
				createLine(data)
			}
		}
	})
}
document.getElementById("q1").onclick=function(){
	clearInterval(window.getX)
	$("#username").val("")
	var data={}
	data.start_date=$("#start_date").val()
	data.end_date=$("#end_date").val()
	if(data.start_date==="" && data.end_date===""){
		showErrorInfo("请您选择一个日期进行查询！")
		return false;
	}
	query(data)

}
document.getElementById("username").onkeyup=function(){
		if(event.keyCode==13){
			clearInterval(window.getX)
			Q2()
		}
}

document.getElementById("q2").onclick=function(){
	clearInterval(window.getX)
			Q2()
}
document.getElementById("q3").onclick=function(){
	window.getX=setInterval(function(){
			query({"real_time":""})
		},1000
	)
}
function Q2(){
	$("#start_date").val("")
	$("#end_date").val("")
	var data={}
	data.username=$("#username").val()
	if(/^ *$/.test(data.username)){
		showErrorInfo("请输入会员号进行查询！")
		return false;
	}
	query(data)
}	
function query(data){
	data.action="general"
	data=JSON.stringify(data)
	$.ajax({
		"url":"/charge/",
		"error":errorAjax,
		"data":{"data":data},
		"dataType":"jsonp",
		"success":function(data){
			if(responseCheck(data)){
				$("#showErrorInfoDIV").hide("fast");
				document.getElementById("shadow").style.display = "none";
				$("#title-x").text(data.start_date + " 至 "+data.end_date)
				createLine(data)
			}
			else{
				clearInterval(getX)
			}
		}
	})
}
document.getElementById("reset-x").onclick=function(){
	clearInterval(window.getX)
	$("tbody>tr").remove()
	$("#start_date").val("")
	$("#end_date").val("")
	$("#username").val("")
}

document.getElementById("username").focus()
//query({"start_date":"today","end_date":""})
if(window.USERNAME=='51032200010'){
	$("#charge2").hide()
}
window.getX=setInterval(function(){
		query({"real_time":""})
	},1000
)
